//
//  ProductsCell.m
//  sensen_ios
//
//  Created by pro on 16/5/20.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ProductsCell.h"

@implementation ProductsCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.contentView.width = (SCREEN_WIDTH - 5 * 3) / 2.0;
        self.contentView.height = self.contentView.width + 30 + 20;
        [self _createViews];
    }
    
    return self;
}
- (void)setModel:(ProductModel *)model {
    _model = model;
    
    [self _layoutUI];
}
- (void)_createViews {
    
    _iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.width, self.contentView.width)];
    [self.contentView addSubview:_iconImgView];
    
   
    _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _iconImgView.bottom, _iconImgView.width, 30)];
    _nameLabel.font = FONT(12);
    _nameLabel.text = @"";
    _nameLabel.textColor = [UIColor darkGrayColor];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.numberOfLines = 2;
    [self.contentView addSubview:_nameLabel];
    
    _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _nameLabel.bottom, _iconImgView.width - 20, 20)];
    _priceLabel.font = FONT(13);
    _priceLabel.text = @"";
    _priceLabel.textColor = [UIColor redColor];
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_priceLabel];
}
- (void)_layoutUI {
    
    // 图片
    [_iconImgView setImageURLStr:_model.img placeholder:DEFAULT_IMAGE];
    // 名字
    _nameLabel.text = _model.name;
    // 价格
    _priceLabel.text = [NSString stringWithFormat:@"￥%@", _model.price];
    //一 创建NSMutableAttributedString 对象
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:_priceLabel.text];
    // 字体
    [attrString addAttribute:NSFontAttributeName
                       value:FONT(12)
                       range:NSMakeRange(_priceLabel.text.length - 2, 2)];
    
    _priceLabel.attributedText = attrString;
}
@end
